﻿// Decompiled with JetBrains decompiler
// Type: SP1.TransFormLibrary
// Assembly: SP1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 4A78F1E7-7FD5-407C-8917-5F99ECC43C34
// Assembly location: C:\Users\KasimGulcan\Desktop\Project\DynaCAD\bin\Debug\SP1.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;

namespace SP1
{
  public static class TransFormLibrary
  {
    public static MatrixTransform MatrixTransFormation(string s)
    {
      MatrixConverter matrixConverter = new MatrixConverter();
      try
      {
        return new MatrixTransform((Matrix) matrixConverter.ConvertFromString(s));
      }
      catch
      {
        Console.WriteLine("Matrix Transform Could not be converted" + s);
        return (MatrixTransform) null;
      }
    }

    public static TranslateTransform TransLateTransformation(string s)
    {
      if (Enumerable.Contains<char>((IEnumerable<char>) s, ','))
        s = s.Replace(" ", "");
      string[] strArray = s.Split(new char[2]
      {
        ',',
        ' '
      });
      try
      {
        return new TranslateTransform(AtributeValueLibrary.DoubleConvertor(strArray[0]), AtributeValueLibrary.DoubleConvertor(strArray[1]));
      }
      catch
      {
        try
        {
          return new TranslateTransform(AtributeValueLibrary.DoubleConvertor(strArray[0]), 0.0);
        }
        catch
        {
          Console.WriteLine("Translate transformation yapılamadı:" + s);
          return (TranslateTransform) null;
        }
      }
    }

    public static RotateTransform RotateTransformation(string s)
    {
      string[] strArray = s.Split(new char[2]
      {
        ',',
        ' '
      });
      if (strArray.Length == 3)
      {
        try
        {
          return new RotateTransform(AtributeValueLibrary.DoubleConvertor(strArray[0]), AtributeValueLibrary.DoubleConvertor(strArray[1]), AtributeValueLibrary.DoubleConvertor(strArray[2]));
        }
        catch
        {
          Console.WriteLine("RotateTransform Yapılamadı:" + s);
          return (RotateTransform) null;
        }
      }
      else if (strArray.Length == 1)
      {
        try
        {
          return new RotateTransform(AtributeValueLibrary.DoubleConvertor(strArray[0]));
        }
        catch
        {
          Console.WriteLine("RotateTransform Yapılamadı:" + s);
          return (RotateTransform) null;
        }
      }
      else
      {
        Console.WriteLine("RotateTransform Yapılamadı:" + s);
        return (RotateTransform) null;
      }
    }

    public static ScaleTransform ScaleTransformation(string s)
    {
      if (Enumerable.Contains<char>((IEnumerable<char>) s, ','))
        s = s.Replace(" ", "");
      string[] strArray = s.Split(new char[2]
      {
        ',',
        ' '
      });
      if (strArray.Length == 2)
      {
        try
        {
          return new ScaleTransform(AtributeValueLibrary.DoubleConvertor(strArray[0]), AtributeValueLibrary.DoubleConvertor(strArray[1]));
        }
        catch
        {
          Console.WriteLine("Scale Yapılamadı:" + s);
          return (ScaleTransform) null;
        }
      }
      else if (strArray.Length == 1)
      {
        try
        {
          return new ScaleTransform(AtributeValueLibrary.DoubleConvertor(strArray[0]), AtributeValueLibrary.DoubleConvertor(strArray[0]));
        }
        catch
        {
          Console.WriteLine("Scale Yapılamadı:" + s);
          return (ScaleTransform) null;
        }
      }
      else
      {
        Console.WriteLine("Scale Yapılamadı:" + s);
        return (ScaleTransform) null;
      }
    }

    public static SkewTransform SkewTransformation(string s)
    {
      try
      {
        if (Enumerable.Contains<char>((IEnumerable<char>) s, 'X'))
          return new SkewTransform(AtributeValueLibrary.DoubleConvertor(s.Replace("X", "")), 0.0);
        if (Enumerable.Contains<char>((IEnumerable<char>) s, 'Y'))
          return new SkewTransform(0.0, AtributeValueLibrary.DoubleConvertor(s.Replace("Y", "")));
        Console.WriteLine("SkewTransformation Yapılamadı:" + s);
        return (SkewTransform) null;
      }
      catch
      {
        Console.WriteLine("SkewTransformation Yapılamadı:" + s);
        return (SkewTransform) null;
      }
    }

    public static UIElement TransForm(UIElement x, string s)
    {
      TransformGroup transformGroup = new TransformGroup();
      if (s.Contains("translate"))
      {
        s = s.Replace("translate", "T");
        int startIndex = s.IndexOf('T');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.TransLateTransformation(s.Substring(startIndex + 2, num - startIndex - 2)));
        }
        catch
        {
          Console.WriteLine("Translate yapılamadı");
        }
      }
      if (s.Contains("rotate"))
      {
        s = s.Replace("rotate", "R");
        int startIndex = s.IndexOf('R');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.RotateTransformation(s.Substring(startIndex + 2, num - startIndex - 2)));
        }
        catch
        {
        }
      }
      if (s.Contains("scale"))
      {
        s = s.Replace("scale", "S");
        int startIndex = s.IndexOf('S');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.ScaleTransformation(s.Substring(startIndex + 2, num - startIndex - 2)));
        }
        catch
        {
        }
      }
      if (s.Contains("skewX"))
      {
        s = s.Replace("skewX", "X");
        int startIndex = s.IndexOf('X');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.SkewTransformation(s.Substring(startIndex + 2, num - startIndex - 2) + "X"));
        }
        catch
        {
        }
      }
      if (s.Contains("skewY"))
      {
        s = s.Replace("skewY", "Y");
        int startIndex = s.IndexOf('Y');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.SkewTransformation(s.Substring(startIndex + 2, num - startIndex - 2) + "Y"));
        }
        catch
        {
        }
      }
      if (s.Contains("matrix"))
      {
        s = s.Replace("matrix", "M");
        int startIndex = s.IndexOf('M');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.MatrixTransFormation(s.Substring(startIndex + 2, num - 2)));
        }
        catch
        {
        }
      }
      x.RenderTransform = (Transform) transformGroup;
      return x;
    }

    public static TransformGroup TransformGroup(string s)
    {
      TransformGroup transformGroup = new TransformGroup();
      if (s.Contains("translate"))
      {
        s = s.Replace("translate", "T");
        int startIndex = s.IndexOf('T');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.TransLateTransformation(s.Substring(startIndex + 2, num - startIndex - 2)));
        }
        catch
        {
          Console.WriteLine("Translate yapılamadı");
        }
      }
      if (s.Contains("rotate"))
      {
        s = s.Replace("rotate", "R");
        Console.WriteLine("s");
        int startIndex = s.IndexOf('R');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.RotateTransformation(s.Substring(startIndex + 2, num - startIndex - 2)));
        }
        catch
        {
        }
      }
      if (s.Contains("scale"))
      {
        s = s.Replace("scale", "S");
        int startIndex = s.IndexOf('S');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.ScaleTransformation(s.Substring(startIndex + 2, num - startIndex - 2)));
        }
        catch
        {
        }
      }
      if (s.Contains("skewX"))
      {
        s = s.Replace("skewX", "X");
        int startIndex = s.IndexOf('X');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.SkewTransformation(s.Substring(startIndex + 2, num - startIndex - 2) + "X"));
        }
        catch
        {
        }
      }
      if (s.Contains("skewY"))
      {
        s = s.Replace("skewY", "Y");
        int startIndex = s.IndexOf('Y');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.SkewTransformation(s.Substring(startIndex + 2, num - startIndex - 2) + "Y"));
        }
        catch
        {
        }
      }
      if (s.Contains("matrix"))
      {
        s = s.Replace("matrix", "M");
        int startIndex = s.IndexOf('M');
        int num = s.IndexOf(')', startIndex);
        try
        {
          transformGroup.Children.Add((Transform) TransFormLibrary.MatrixTransFormation(s.Substring(startIndex + 2, num - 2)));
        }
        catch
        {
        }
      }
      return transformGroup;
    }
  }
}
